package com.yanqu.road.server.cmd.banquet.crossBanquet;

import com.yanqu.road.entity.banquet.UserCrossBanquetData;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_BANQUET_CROSS_GET_ALL_REWARD,desc = "一键领取盛宴奖励")
public class GetBabqyerPopRewardQuicklyCmd extends AbstractCommand {
    private String banquetId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossBanquetProto.BanquetGetAllPopRewardReq req = CrossBanquetProto.BanquetGetAllPopRewardReq.parseFrom(packet.getBytes());
        banquetId = req.getBanquetId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BanquetModule.class).getAllCrossBanquetPopReward(banquetId);
        UserCrossBanquetData banquet = CrossBanquetMgr.getBanquet(banquetId);
        if (banquet == null || CrossBanquetMgr.isBanquetOver(banquet.getBanquetId())) {
            return;
        }
        player.getModule(BanquetModule.class).crossBanquetPopRewardSync(banquet);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            CrossBanquetProto.BanquetGetAllPopRewardResp.Builder resp = CrossBanquetProto.BanquetGetAllPopRewardResp.newBuilder();
            resp.setRet(ret);
            resp.setRewards("");
            player.sendPacket(ClientProtocol.U_BANQUET_CROSU_GET_ALL_REWARD, resp);
        }
    }
}
